<?php
namespace App\Controllers;

use App\Services\StatisticsService;
use common\enum\CommonEnum;
use common\utils\SysCode;
use Illuminate\Http\Request;

/**
 * 导出Controller
 * Class DownController
 * @package App\Controllers
 */
class DownController
{
    public static function exportAllStatistics(Request $request)
    {
        $params = $request->input();
        $today = date ('Y-m-d');
        $params['date_begin'] = isset($params['date_begin']) ? $params['date_begin'] : $today;
        $params['date_end'] = isset($params['date_end']) ? $params['date_end'] : $today;
        $params['page'] = isset($params['page']) ? $params['page'] : CommonEnum::PAGE_DEFAULT;
        $params['page_size'] = isset($params['page_size']) ? $params['page_size'] : CommonEnum::PAGE_SIZE_TWENTY;
        // 排序设置
        $params['order'] = (isset($params['order']) && in_array($params['order'], ['profit','bet_amount','validbet','bet_number','bonus_amount','contribute_amount'])) ? $params['order'] : 'profit';
        $params['desc'] = (isset($params['desc']) && in_array($params['desc'], ['asc','desc','ASC','DESC'])) ? $params['desc'] : 'desc';
        if($params['date_begin']>$today || $params['date_end']>$today){
            error_exit(SysCode::INVALID_ARGUMENT, '时间不能是未来时间');
        }
        if($params['date_begin']>$params['date_end']){
            error_exit(SysCode::INVALID_ARGUMENT, '开始时间不可超过截止时间');
        }
        return  StatisticsService::exportAllStatistics($params);
    }

}